package ywpt.service.knowledge;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.KnowLib;
import ywpt.model.PeopleInfo;
@Service("knowLibService")
public class KnowLibServiceImpl  extends HibernateEntityDao<KnowLib> implements KnowLibService{
	public KnowLibServiceImpl(){
	}

	
	@Override
	public KnowLib getKnowLibById(Long id) {
		return this.get(id);
	}

	@Override
	public int getKnowLibCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<KnowLib> getKnowLibs(DetachedCriteria query, int pageSize, int startIndex) {
		return this.findAllByCriteria(query, pageSize, startIndex);
	}

	@Override
	public void removeKnowLib(Long id) {
		super.removeById(id);
	}

	@Override
	public void saveKnowLib(KnowLib knowLib, Long checkerId) {
		if (checkerId!=null) {
			knowLib.setChecker(this.get(PeopleInfo.class, checkerId));
		}
		super.save(knowLib);
	}

	@Override
	public void updatKnowLib(KnowLib knowLib, Long checkerId) {
		if (checkerId!=null) {
			knowLib.setChecker(this.get(PeopleInfo.class, checkerId));
		}
		super.update(knowLib);
	}



	@SuppressWarnings("unchecked")
	@Override
	public List<KnowLib> getKnowLibs(DetachedCriteria query) {
		return this.findAllByCriteria(query);
	}

}
